package Exception;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.InetAddress;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import GUI.LogGUI;
import Log.Log;

public class ICMLog 
{
	public static ICMLog log =null;
	private String logFileName;

	private ICMLog()
	{ 
		String currentDir = System.getProperty("user.dir");
		String path = currentDir+"/logFiles";
		File dir=new File(path);
		
	     if(! dir.exists())
	     {
	    	 dir.mkdir();
	     }
	     
	     path = dir.getPath();
	     DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
	     Calendar cal = Calendar.getInstance();
	     logFileName =  path +"\\" + dateFormat.format(cal.getTime()) + ".txt";
	      File file = new File(logFileName);
	      
	      try 
	      {
			 if( file.createNewFile() == true)
			 {
				 
			 }
		  } 
	      catch (IOException e) 
	      {
			// TODO Auto-generated catch block
			e.printStackTrace();
		  }
	}
	public static ICMLog getInstance()
	{
		if (null == log)
		{
			log = new ICMLog();
		}
		return log;
	}
	
	public void writeInLog(String msg)
	{
		FileWriter fstream;
		try 
		{
			fstream = new FileWriter(logFileName, true);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(msg + "\n");
			out.close();
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} //true tells to append data.
	}
	

	public static void main(String[] args) 
	{
		int i,j,inc=0;
		for(i=1;i<=3;i++)
			for(j=1 ; j<=34 ; j++)
			{
				ICMLog.getInstance().writeInLog("INSERT INTO status (id,MainStatus,StepStatus) VALUES ("+ ++inc + "," + i + "," + j +");");
			}
		 System.out.println("End");
		/*FileWriter fstream;
		try 
		{
			msg = 
			fstream = new FileWriter("C:/Users/Shimon Arzuan/Desktop/61143-Sp13 Semester Project (1)", true);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(msg + "\n");
			out.close();
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} //true tells to append data.*/
		
		/*ICMLog.getInstance().writeInLog("INSERT INTO worker (userid, Workertype) VALUES ('1','1');");
		int i;
		for(i=2 ; i<20 ; i++)
		{
		   ICMLog.getInstance().writeInLog("INSERT INTO worker (userid, Workertype) VALUES (' " + i + " ','2');");
		}
		for(; i<30 ; i++)
		{
		   ICMLog.getInstance().writeInLog("INSERT INTO worker (userid, Workertype) VALUES (' " + i + " ','3');");
		}
		   System.out.println("End");
	}*/
	/*
		    	  InetAddress addr;
		    	  addr = InetAddress.getLocalHost();
		    	  String hostname = addr.getHostName();
		    	  System.out.println("addr " + addr);
		    	  System.out.println("hostname " + hostname);
	 */
		//File file = new File("C:/EclipseWorkSpace/ICM_System/Files/1/0.pdf");
		
	}
}
